package flink_source;
import org.apache.flink.api.common.serialization.SimpleStringSchema;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.streaming.connectors.kafka.FlinkKafkaConsumer;

import java.util.Properties;

/**
 * @author Spring_Hu
 * @date 2021/10/10 11:40
 */
public class Flink_sourceFromKafka {
    public static void main(String[] args) throws Exception {
        StreamExecutionEnvironment ens = StreamExecutionEnvironment.getExecutionEnvironment();
        Properties properties = new Properties();
        properties.setProperty("bootstrap.servers", "hadoop102:9092,hadoop103:9092,hadoop104:9092");
        properties.setProperty("group.id", "Flink01_Source_Kafka");
        properties.setProperty("auto.offset.reset", "latest");

        DataStreamSource<String> source = ens.addSource(new FlinkKafkaConsumer<>("topic",
                new SimpleStringSchema(), properties));

        source.print();

        ens.execute();
    }
}
